import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/product',
      meta: { title: '答题', icon: 'dashboard' },
    children: [
        {
            name: 'product',
            path: 'product',
            component: () => import('@/views/banner/index'),
            meta: { title: '奖品', icon: 'dashboard' }
        },
        {
            name: 'category',
            path: 'category',
            component: () => import('@/views/category/index'),
            meta: { title: '答题分类', icon: 'dashboard' }
        },
        {
            name: 'question',
            path: 'question',
            component: () => import('@/views/question/index'),
            meta: { title: '题库管理', icon: 'dashboard' }
        },
        {
            name: 'record',
            path: 'record',
            component: () => import('@/views/record/index'),
            meta: { title: '中奖记录', icon: 'dashboard' }
        },
        {
            name: 'count',
            path: 'count',
            component: () => import('@/views/count/index'),
            meta: { title: '中奖统计', icon: 'dashboard' }
        },
        {
            name: 'user',
            path: 'user',
            component: () => import('@/views/member/index'),
            meta: { title: '用户管理', icon: 'dashboard' }
        }
    ]
  },
    {
        path: '/policy',
        component: Layout,
        redirect: '/policy/index',
        meta: { title: '用户协议', icon: 'dashboard' },
        children: [
            {
                path: 'index',
                name: 'policy',
                component: () => import('@/views/policy/index'),
                meta: { title: '用户协议', icon: 'dashboard' }
            }
        ]
    },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
